package com.youlai.boot.system.controller;

import com.youlai.boot.common.annotation.Log;
import com.youlai.boot.common.annotation.RepeatSubmit;
import com.youlai.boot.common.enums.LogModuleEnum;
import com.youlai.boot.system.service.SpotTravelService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.system.model.form.SpotTravelForm;
import com.youlai.boot.system.model.query.SpotTravelQuery;
import com.youlai.boot.system.model.vo.SpotTravelVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 旅行社数据前端控制层
 *
 * @author lwb
 * @since 2025-06-29 21:14
 */
@Tag(name = "旅行社数据接口")
@RestController
@RequestMapping("/api/v1/spotTravels")
@RequiredArgsConstructor
public class SpotTravelController  {

    private final SpotTravelService spotTravelService;

    //@Operation(summary = "旅行社数据分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('system:spotTravel:query')")
    public PageResult<SpotTravelVO> getSpotTravelPage(SpotTravelQuery queryParams ) {
        IPage<SpotTravelVO> result = spotTravelService.getSpotTravelPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增旅行社数据")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('system:spotTravel:add')")
    @Log(value = "新增旅行社数据", module = LogModuleEnum.OTHER)
    @RepeatSubmit(expire = 3)
    public Result<Void> saveSpotTravel(@RequestBody @Valid SpotTravelForm formData ) {
        boolean result = spotTravelService.saveSpotTravel(formData);
        return Result.judge(result);
    }

    //@Operation(summary = "获取旅行社数据表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('system:spotTravel:edit')")
    public Result<SpotTravelForm> getSpotTravelForm(
        @Parameter(description = "旅行社数据ID") @PathVariable Long id
    ) {
        SpotTravelForm formData = spotTravelService.getSpotTravelFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改旅行社数据")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('system:spotTravel:edit')")
    @Log(value = "修改旅行社数据", module = LogModuleEnum.OTHER)
    @RepeatSubmit(expire = 3)
    public Result<Void> updateSpotTravel(
            @Parameter(description = "旅行社数据ID") @PathVariable Long id,
            @RequestBody @Validated SpotTravelForm formData
    ) {
        boolean result = spotTravelService.updateSpotTravel(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除旅行社数据")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('system:spotTravel:delete')")
    @Log(value = "删除旅行社数据", module = LogModuleEnum.OTHER)
    public Result<Void> deleteSpotTravels(
        @Parameter(description = "旅行社数据ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = spotTravelService.deleteSpotTravels(ids);
        return Result.judge(result);
    }
}
